$(document).ready(function(){
    $('#search-text').keyup(function(){
        var uname = $(this).val();
        var datastring = 'name=' + uname;
        if(uname.length>0){
            $.ajax({
                type: 'GET',
                url: './SourceCode/search_user.php',
                data: datastring,
                beforeSend: function(){
                    $('#chat-left-user-list').empty();
                    $('#chat-left-user-list').addClass('loading');  
                },
                success:function(server_response)
                {
                    $('#chat-left-user-list').html(server_response).fadeIn();
                    if($('#chat-left-user-list').hasClass('loading')){
                        $('#chat-left-user-list').removeClass('loading');
                    }
                }
            });
        }else{
            $.ajax({
                type: 'GET',
                url: './SourceCode/load_user.php',
                data: datastring,
                beforeSend: function(){
                    $('#chat-left-user-list').empty();
                    $('#chat-left-user-list').addClass('loading');  
                },
                success:function(server_response)
                {
                    $('#chat-left-user-list').html(server_response).fadeIn();
                    if($('#chat-left-user-list').hasClass('loading')){
                        $('#chat-left-user-list').removeClass('loading');
                    }
                }
            });
        }
    });
});